<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/operateTag" prefix="o"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>积分卡管理</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/page/head.jsp"></jsp:include>
<script type="text/javascript">
		//页面打开加载
		$(document).ready(function(){
			
		    $('#mgrTable').datagrid({
       			height: 500,
		        pageSize: 20,//每页显示的记录条数，默认为10  
		        pageList: [10,15,20],//可以设置每页记录条数的列表
				nowrap: true,
        		border: true,  
				striped: true,
				collapsible: false,
				url:path+'/scoreCard/list.do',
				sortName: 'id',
				sortOrder: 'asc',
				remoteSort: false,
				idField:'id',
				pagination:true,
				rownumbers:true,
				toolbar:'#toolbar'
			});
			var p = $('#mgrTable').datagrid('getPager');
			$(p).pagination({   
		        beforePageText: '第',//页数文本框前显示的汉字  
		        afterPageText: '页    共  {pages} 页',
		        displayMsg: '当前显示  {from} - {to} 条记录   共  {total} 条记录'
		    });
			
		});
		
		
		var url;
		
		//添加用户
		function add(){
			window.location = path+"/scoreCard/init.do?type=add";
		}
		
		//移除用户
		function remove(){
			var rows = $('#mgrTable').datagrid('getSelections');   //获取选中行信息
			
			if(rows){
				var ids = [];
				for(var i=0;i<rows.length;i++){
					ids.push(rows[i].id);
				}
				//循环所选的行
				/* for(var i =0;i<rows.length;i++){
					var index = $('#mgrTable').datagrid('getRowIndex',rows[i]);//获取某行的行号
					$('#mgrTable').datagrid('deleteRow',index);	//通过行号移除该行
				} */

				alert(rows.length);
				var submit = function (v, h, f) {
				    if (v == 'ok'){
				    	url = path +"/scoreCard/delete.do?ids="+ids.join(',')+"&t="+new Date().getTime();
						$.ajax({
						  url: url,
						  success: function(data) {
							   if(data == "1")
							   {
									$('#mgrTable').datagrid('reload');
									$('#mgrTable').datagrid('clearSelections');
									//清空ids
									
									alertBox("操作成功！");
							   } else {
									alertBox("操作失败！");
							   }
						  }
						});
				    }
				    	
				    return true; //close
				};
				
				$.jBox.confirm("确定要删除吗？", "提示", submit);
				
			}else{
				alertBox("请选择需要删除的会员卡！");
			}
		}
		
		//刷新
		function refresh(){
			$('#mgrTable').datagrid('reload');
			$('#mgrTable').datagrid('clearSelections');
		}
		
		//根据条件进行模糊查询
		function search(){
			var score = $('#score').val();                  //获取筛选条件中的scoreStar
			var card = $('#card').val();                  //获取筛选条件中的积分卡号卡号
			var scoreEnd = $('#scoreEnd').val();
			var effectiveTimeStart = $('#effectiveTimeStart').datebox('getValue');                  //获取筛选条件中的开始时间
			var effectiveTimeEnd = $('#effectiveTimeEnd').datebox('getValue');                     //获取筛选条件中的结束时间
			
			$('#mgrTable').datagrid('reload',{score:score,card:card,scoreEnd:scoreEnd,effectiveTimeStart:effectiveTimeStart,effectiveTimeEnd:effectiveTimeEnd});
		}
		
		function clean(){
			$('#score').attr('value','');
			$('#card').attr('value','');
			$('#scoreEnd').attr('value','');
			$('#effectiveTimeStart').datebox('setValue','');
			$('#effectiveTimeEnd').datebox('setValue','');
		}
		
	</script>

</head>

<body>
	<div class="right">
		<h1>
			<b>积分卡管理</b><span><img
				src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span>
		</h1>
		<div class="ri_main">
			<table width="90%" border="0" cellspacing="0" cellpadding="4">
				<tr>
					<td style="vertical-align: middle;">
						<label>积分卡号：</label>
						<input class="easyui-validatebox" type="text" name="card" id="card" />
						&nbsp;&nbsp;&nbsp;<label>积分：</label> 
						<input class="easyui-validatebox" type="text" name="score" id="score" /> 
						<label>到</label>
						<input class="easyui-validatebox" type="text" name="scoreEnd" id="scoreEnd" /><br />
						<label>有效时间：</label>
						<input class="easyui-datetimebox" type="text" name="effectiveTimeStart" id="effectiveTimeStart" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>到</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<input class="easyui-datetimebox" type="text" name="effectiveTimeEnd" id="effectiveTimeEnd" />
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="button" onclick="search()" value="查询" />
						<input type="button" onclick="clean()" value="清除" /></td>
				</tr>
			</table>
			<div id="toolbar">
				<a href="javascript:void(0);" onclick="add()" class="easyui-linkbutton" iconCls="icon-add">新增</a>
				<a href="javascript:void(0);" onclick="remove()" class="easyui-linkbutton" iconCls="icon-remove">删除</a>
				<a href="javascript:void(0);" onclick="refresh()" class="easyui-linkbutton" iconCls="icon-reload">刷新</a>
			</div>
			<table id="mgrTable">
				<thead>
		 			<tr>
		 				<th field="ck" checkbox="true"></th>
						<th field="card" width="100">卡号</th>
		 				<th field="password" width="100">密码</th>
						<th field="score" width="100">积分</th>
						<th field="status" width="100">状态</th>
						<th field="startime" width="145">有效起始时间</th>
						<th field="endtimne" width="145">有效结束时间</th>
		 			</tr>
		 		</thead>
			</table>
		</div>
	</div>
</body>
</html>
